/**
 * author:Administrator
 * date:2016/1/4
 * desc: koa-better-body in router
 */

'use strict';

var bodyParser = require('koa-better-body');
var koaBody = bodyParser({});

var Router = require('koa-router');
var __pathPrefix = '/test';
var router = new Router({prefix: __pathPrefix});
module.exports = router.routes();

/**
 * post /test
 { "foo":"bar" }
 */
router.post('/', koaBody, function*() {
  var json = this.request.body.fields;
  console.log(json);
  this.body = json;
});

/**
 * 获取某个账户信息
 */
router.get('/:id', function*() {
  var id = this.params.id;
  var retObj = {id: id};
  this.body = retObj;
});

/**
 * 修改
 {"name":"xx","money":"xx"}
 */
router.put('/:id', koaBody, function*() {
  var id = this.params.id;
  var json = this.request.body.fields;
  json.id = id;
  this.body = json;
});

router.delete('/:id', function*() {
  var id = this.params.id;
  var retObj = {id: id};
  this.body = retObj;
});